package Collecion;

import java.util.ArrayList;
import java.util.List;


public class lianxiText {  
    public static void main(String[] args) {
        Student s1 = new Student(25,"蔡徐坤","男","xxxx",123,"湖南吉首");
        Student s2 = new Student(25,"鸡哥","男","你干嘛",123,"湖南吉首");
        List<Student> list = new ArrayList<>();
        //添加
        list.add(s1);
        list.add(s2);
        System.out.println(list);
        //删除
        list.remove(s1);
        System.out.println(list);
        //查询有鸡哥，有则将鸡哥改为坤哥，无在显示查无此人。。。
        int index=findIndexof(list,"鸡哥");
        if (index<0) {
            System.out.println("查无此人");
        }else {
            Student student= list.get(index);//获得这个人
            //修改名字
            student.setName("坤哥");
        }
        System.out.println("list="+list);
    }

    private static int findIndexof(List<Student> list, String name) {
        int i=0;
        for (i=0;i<list.size();i++){
            if (list.get(i).getName("").equals(name)){
                break;
            }
        }
        if (i==list.size()){
            return -1;
        }else {
            return 1;
        }
    }


}

class Student {
    private int age;
    private String name;
    private String sex;
    private String id;
    private int phone;
    private String address;

    public Student(int age, String name, String sex, String id, int phone, String address) {
        this.age = age;
        this.name = name;
        this.sex = sex;
        this.id = id;
        this.phone = phone;
        this.address = address;
    }

    public Student() {
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName(String 坤哥) {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getPhone() {
        return phone;
    }

    public void setPhone(int phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", id='" + id + '\'' +
                ", phone=" + phone +
                ", address='" + address + '\'' +
                '}';
    }
}